<!DOCTYPE html>
<html>
<title>菜单管理</title>
<head>
    <link href="/css/layui/css/layui.css" rel="stylesheet">
    <link href="/css/hadmin/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
    <link href="/css/hadmin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/hadmin/css/animate.css" rel="stylesheet">
    <link href="/css/hadmin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/css/hadmin/css/animate.css" rel="stylesheet">
    <link href="/css/bootstrap-select.min.css" rel="stylesheet">
    <link href="/css/multi-select.dist.css" rel="stylesheet">
</head>

<div class="wrapper wrapper-content animated fadeInUp">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-title">
                    <h5>菜单管理</h5>
                </div>
                <div class="ibox-content">
                    <div class="form-group">
                        <form class="form-inline" method="post" action="/auth/index" id="form">
                            <select name="id" id="selectID" class="form-control">
                                <option value="0">请选择菜单</option>
                                <?php foreach($root as $v): ?>
                                    <option value="<?=$v['Auth']['id']?>"><?=$v['Auth']['auth_name']?></option>
                                <?php endforeach; ?>
                            </select>
                            <button type="submit" class="btn btn-primary" id="search"> 搜索菜单</button>
                            <a class="btn btn-primary radius" data-toggle="modal" data-target="#myModal">添加菜单</a>
                        </form>
                    </div>
                </div>
                <div class="page-container">
                    <div class="mt-20">
                        <table class="table table-hover table-bordered datatable">
                            <thead>
                            <tr>
                                <th width="80">ID</th>
                                <th width="100">菜单名称</th>
                                <th width="100">url</th>
                                <th width="40">父级id</th>
                                <th width="160">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                                <?php foreach($data as $value): ?>
                                <tr>
                                    <td><?= $value['id']?></td>
                                    <td><?= $value['auth_name']?></td>
                                    <td><?= $value['path']?></td>
                                    <td><?= $value['pid']?></td>
                                    <td class="td-manage">
                                        <a class="layui-icon layui-icon-edit"  onclick="edit(<?=$value['id']?>,'<?=$value['auth_name']?>','<?=$value['path']?>',<?=$value['is_menu']?>,'<?=$value['pid']?>')" data-toggle="modal" data-target="#myModal"></a>
                                        <a class="layui-icon layui-icon-subtraction" onclick="del(<?=$value['id']?>)"></a>
                                    </td>
                                </tr>
                                    <?php foreach($value['son'] as $v): ?>
                                    <tr>
                                        <td><?= $v['id']?></td>
                                        <td>&nbsp;&nbsp;<?="|---".$v['auth_name']?></td>
                                        <td><?= $v['path']?></td>
                                        <td><?= $v['pid']?></td>
                                        <td class="td-manage">
                                            <a class="layui-icon layui-icon-edit"  onclick="edit(<?=$v['id']?>,'<?=$v['auth_name']?>','<?=$v['path']?>',<?=$v['is_menu']?>,'<?=$v['pid']?>')" data-toggle="modal" data-target="#myModal"></a>
                                            <a class="layui-icon layui-icon-subtraction" onclick="del(<?=$v['id']?>)"></a>
                                        </td>
                                    </tr>
                                    <?php endforeach; ?>
                                <?php endforeach;?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal"  data-backdrop="false" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-lg" role="document" >
        <div class="modal-content" >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"  aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">权限修改</h4>
            </div>
            <div class="modal-body">
                <form id="statusForm">
                    <div class="form-group ">
                        <label for="id" class="control-label">权限id</label>
                        <input type="text" disabled name="prop_name" id="id" class="form-control"/>
                    </div>
                    <div class="form-group ">
                        <label for="auth_name1" class="control-label">权限名</label>
                        <input type="text" placeholder="请输入权限名"  id="auth_name1"  class="form-control"/>
                    </div>
                    <div class="form-group ">
                        <label for="is_menu1" class="control-label">是否菜单权限</label>
                        <select id="is_menu1"  class="form-control" >
                            <option value="1">是否菜单权限(默认是)</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                    <div class="form-group ">
                        <label for="path1" class="control-label">url地址</label>
                        <input type="text" placeholder="请输入url地址" id="path1" class="form-control"/>
                    </div>
                    <div class="form-group ">
                        <label for="auth1" class="control-label">父级权限</label>
                        <select id="auth1" class="form-control" >
                            <option value="0">请选择菜单(默认顶级菜单)</option>
                            <?php foreach($rootMenu as $v): ?>
                                <option value="<?= $v['id'] ?>"><?= $v['auth_name']?></option>
                                <?php foreach($v['son'] as $v1): ?>
                                    <option value="<?= $v1['id'] ?>">&nbsp;&nbsp;|--<?= $v1['auth_name']?></option>
                                <?php endforeach; ?>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">返回</button>
                <button type="button" id="ajax_submit1" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>
</div>


<script src="/css/hadmin/js/jquery.min.js?v=2.1.4"></script>
<script src="/css/hadmin/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/css/hadmin/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/css/hadmin/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/css/hadmin/js/plugins/layer/layer.min.js"></script>
<script src="/css/hadmin/js/index.js"></script>
<script src="/css/hadmin/js/plugins/toastr/toastr.min.js"></script>
<script src="/js/jquery.fancybox.min.js"></script>
<script src="/js/cupload.js"></script>

<script>
    $("#selectID").val("<?=$id?>");
    //加载模态框
    function edit(id,auth_name,path,is_menu,pid) {
        $("#id").val(id);
        $("#auth_name1").val(auth_name);
        $("#path1").val(path);
        $("#is_menu1").val(is_menu);
        $("#auth1").val(pid);
    };

    //修改ajax
    $("#ajax_submit1").click(function () {
        var data = {
            'id':$("#id").val(),
            'auth_name':$("#auth_name1").val(),
            'path':$("#path1").val(),
            'is_menu':$("#is_menu1").val(),
            'pid':$("#auth1").val(),
        };
        $.ajax({
            'url': '/auth/editAuth',
            'type':'post',
            'data':data,
            'dataType':"json",
            'success':function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg, {time: 1000, icon: 1});
                } else {
                    layer.msg(res.msg, {time: 1000, icon: 2});
                }
                setTimeout(function () {
                    window.location.reload();
                }, 800)
            }
        })
    });
    
    //删除
    function del(id) {
        var data ={'id':id};
        $.ajax({
            'url':'/auth/delAuth',
            'type':'post',
            'dataType': 'json',
            'data': data,
            'success':function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg, {time: 1000, icon: 1});
                } else {
                    layer.msg(res.msg, {time: 1000, icon: 2});
                }
                setTimeout(function () {
                    window.location.reload();
                },800);
            }
        });
    };

</script>
</html>